package com.nhjf.dao.oneOnOneLive;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.oneOnOneLive.OneOnOneLive;
import com.nhjf.pojo.qo.oneOnOneLive.OneOnOneLiveQo;
@Repository
public class OneOnOneLiveDao extends BaseDao<OneOnOneLive, OneOnOneLiveQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, OneOnOneLiveQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("student", qo.isSeachStudent()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("teacher", qo.isSeachTeacher()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getConfirmationStatus()!=null) {
				criteria.add(Restrictions.eq("confirmationStatus",qo.getConfirmationStatus()));
			}
			if(qo.getEndTime()!=null) {
				criteria.add(Restrictions.eq("endTime",qo.getEndTime()));
			}
			if(qo.getStartingTime()!=null) {
				criteria.add(Restrictions.eq("startingTime",qo.getStartingTime()));
			}
			if(qo.getLiveTime()!=null) {
				criteria.add(Restrictions.eq("liveTime",qo.getLiveTime()));
			}
			if(qo.getOneOnOneLiveId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getOneOnOneLiveId()));
			}
			if(qo.getPeriod()!=null) {
				criteria.add(Restrictions.eq("period",qo.getPeriod()));
			}
			if(StringUtils.isNotBlank(qo.getStudentDescription())) {
				criteria.add(Restrictions.eq("studentDescription",qo.getStudentDescription()));
			}
			if(qo.getStudentId()!=null) {
				criteria.add(Restrictions.eq("student.id",qo.getStudentId()));
			}
			if(qo.getTeacherId()!=null) {
				criteria.add(Restrictions.eq("teacher.id",qo.getTeacherId()));
			}
		}
		return criteria;
	}

	@Override
	protected Class<OneOnOneLive> getEntityClass() {
		// TODO Auto-generated method stub
		return OneOnOneLive.class;
	}

}
